﻿// Inner Fire 游戏引擎库
// 渲染贴图
//
// Copyright (c) 2024 by 尔西大帝. All rights reserved.
//
// 这个类用于离屏渲染贴图的基类。比如阴影贴图，环境光遮蔽等等。
// 根据《DirectX12游戏开发实战》中的工具类修改。原作者：Frank Luna
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2024-12-04

#pragma once

#include <dx/core/dx_core.h>
#include <string>
#include <static_string.h>

namespace ifire::dx {

enum class DebugLayer : int {
  None = 0,   // 不显示任何调试层
  Shadow, // 显示阴影贴图
  Ssao,   // 显示屏幕环境光遮蔽贴图
  Count
};

class RenderTexture {
public:
  RenderTexture(ID3D12Device* device, UINT width, UINT height, DXGI_FORMAT format);
  RenderTexture(const RenderTexture& rhs) = delete;
  RenderTexture& operator=(const RenderTexture& rhs) = delete;
  ~RenderTexture() = default;

  UINT Width() const { return width_; }
  UINT Height() const { return height_; }
  ID3D12Resource* Resource() const { return resource_.Get(); }
  D3D12_VIEWPORT Viewport() const { return viewport_; }
  D3D12_RECT ScissorRect() const { return scissor_rect_; }

  void OnResize(UINT width, UINT height);


protected:
  // 创建资源
  virtual void BuildResource() = 0;
  virtual void BuildDescriptors() = 0;

protected:
  ID3D12Device* device_ = nullptr;
  UINT width_ = 0;
  UINT height_ = 0;
  Microsoft::WRL::ComPtr<ID3D12Resource> resource_ = nullptr;

  D3D12_VIEWPORT viewport_;
  D3D12_RECT scissor_rect_;
  
  DXGI_FORMAT format_;

private:
};

DebugLayer ReadDebugLayer(ikit::sstr name);

} // namespace ifire
